<?php
namespace QnuiRings\Controller;
use Think\Controller;
// 软件名称：互动折扣王-连环折扣-满就送折扣
// 代码日期：v3.0 2018-7-14
// 作者：杨道泉
// 文件名：QnuiZhekouLimitController.class.php
// 功能： 使用千牛UI发布限购折扣

class QnuiZhekouLimitController extends QnuiBaseController {

    public function create_limit_active(){
        $this->tagName=I("tagName");
        $this->startTime=date("Y-m-d H:i:s",I("startTime"));
        $this->endTime=date("Y-m-d H:i:s",I("endTime"));
        $this->notice=I("notice");
        $this->task_tag_id=I("task_tag_id");
        $this->task_tag_name=I("task_tag_name");
        
        $WEI = D("UmpWeiZheRing");
        $WEI->name = $this->tagName;
        $WEI->description = $this->notice;
        $WEI->tag_id = $this->task_tag_id;
        $WEI->start_time = $this->startTime;
        $WEI->end_time = $this->endTime;
        $WEI->ParticipateRange = true;
        $resp = pre_resp($WEI->CreateActivity());
        
        $this->ajaxReturn($resp);
    }
	public function remove_active(){
		$actId = I("activity_id");
		$WEI = D("UmpWeiZheRing");
		$WEI->actId = $actId;
		$resp = pre_resp($WEI->removeActivity());
		$this->ajaxReturn($resp);
	}
	public function remove_detial(){
		$detail_id = I("detail_id");
		$WEI = D("UmpWeiZheRing");
		$WEI->detailId = $detail_id;
		$resp = pre_resp($WEI->removeDetail());
		$this->ajaxReturn($resp);
	}
    public function add_limit_to_active(){
        $actId = I("activity_id");
        $promotion_type = I("promotion_type");
        $promotion_value = I("promotion_value");
        $price = I("price");
        $is_limit_buy = I("is_limit_buy");
        $limit_count = I("limit_count")?I("limit_count"):9999;
        $item_id = I("item_id");
        $tag_id = I("tag_id");
        
        if($promotion_type==1){//打折的变更为减钱
            $promotion_value=($price-$price*($promotion_value/10))*100;
        }else{
            $promotion_value=$promotion_value*100;
        }
        
        $itemSet["itemId"] = $item_id;
        $itemSet["tag_id"] = $tag_id;
        $itemSet["limitCount"] = $is_limit_buy?$limit_count:9999;
        $itemSet["countAt"] = 0;
        $itemSet["enableMultiple"] = false;
        $itemSet["amountAt"] = 0;
        $itemSet["priceMultiple"] = false;
        $itemSet["calcDecrMultiple"] = true;
        $itemSet["decrease"] = true;
        $itemSet["decreaseMoney"] = $promotion_value;
        $itemSet["isAddTag"] = false;
        $itemSet["addTagId"] = 0;
        $itemSet["isRemoveTag"] = false;
        $itemSet["removeTagId"] = 0;
        
        $WEI = D("UmpWeiZheRing");
        $WEI->actId = $actId;
        $WEI->itemSet = $itemSet;
        $resp = pre_resp($WEI->CreateItemDetail());
        $resp->params = $itemSet;
        $this->ajaxReturn($resp);
    }
	public function edit_limit_item(){
		$actId = I("activity_id");
        $promotion_type = I("promotion_type");
        $promotion_value = I("promotion_value");
        $price = I("price");
        $is_limit_buy = I("is_limit_buy");
        $limit_count = I("limit_count")?I("limit_count"):9999;
        $item_id = I("item_id");
        $tag_id = I("tag_id");
        $detail_id = I("detail_id");
        
        if($promotion_type==1){//打折的变更为减钱
            $promotion_value=($price-$price*($promotion_value/10))*100;
        }else{
            $promotion_value=$promotion_value*100;
        }
		
		$itemSet["itemId"] = $item_id;
        $itemSet["tag_id"] = $tag_id;
        $itemSet["limitCount"] = $is_limit_buy?$limit_count:9999;
        $itemSet["countAt"] = 0;
        $itemSet["enableMultiple"] = false;
        $itemSet["amountAt"] = 0;
        $itemSet["priceMultiple"] = false;
        $itemSet["calcDecrMultiple"] = true;
        $itemSet["decrease"] = true;
        $itemSet["decreaseMoney"] = $promotion_value;
        $itemSet["isAddTag"] = false;
        $itemSet["addTagId"] = 0;
        $itemSet["isRemoveTag"] = false;
        $itemSet["removeTagId"] = 0;
		
		$WEI = D("UmpWeiZheRing");
        $WEI->actId = $actId;
        $WEI->itemSet = $itemSet;
        $WEI->detailId = $detail_id;
        $resp = pre_resp($WEI->editItemDetail());
        $resp->params = $itemSet;
        $this->ajaxReturn($resp);
	}
	public function get_items_in_active(){
		$act_id = I("activity_id");
		$page = I("page");
		$page_size = I("page_size");
		
		$WEI = D("UmpWeiZheRing");
		$WEI->actId = $act_id;
		$WEI->page = $page;
		$WEI->page_size = $page_size;
		$ret = pre_resp($WEI->getItemDetial());

		$this->ajaxReturn($ret);
	}
}